﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BTS.Model;
using System.Data.SqlClient;
using BTS.DAL;
using System.Data;

namespace BTS.BLL
{
    public class BcontentBLL
    {
        private BcontentDAL dal = new BcontentDAL();

        /// <summary>
        /// 获取内容对象
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Bcontent GetBcontent(string id)
        {
            SqlParameter[] ps = new SqlParameter[] { 
                new SqlParameter("@id",id)
            };
            string sql = "select top 1 * from bcontent where id=@id";
            List<Bcontent> list = dal.GetList<Bcontent>("", "", CommandType.Text, sql, ps);
            if (list.Count > 0)
                return list[0];
            else
                return null;
        }

        /// <summary>
        /// 更改
        /// </summary>
        /// <param name="bc"></param>
        /// <returns></returns>
        public bool UpdateBcontent(Bcontent bc)
        {
            SqlParameter[] ps = new SqlParameter[] { 
                new SqlParameter("@id",bc.Id),
                new SqlParameter("@content",bc.Content)
            };
            string sql = "update bcontent set content=@content where id=@id";
            bool b = dal.AddOrUpdateOrDelete("", "", CommandType.Text, sql, ps);
            return b;
        }

        /// <summary>
        /// 单个删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteBcontent(string id)
        {
            SqlParameter[] ps = new SqlParameter[] { 
                new SqlParameter("@id",id)
            };
            string sql = "delete from bcontent where id=@id";
            bool b = dal.AddOrUpdateOrDelete("", "", CommandType.Text, sql, ps);
            return b;
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="indexs"></param>
        /// <returns></returns>
        public bool DeleteBcontents(string indexs)
        {
            string sql = "delete from bcontent where id in (" + indexs + ")";
            return dal.AddOrUpdateOrDelete("", "", CommandType.Text, sql, null);
        }
    }
}
